package com.bo.wei.chen.mybatis.design;

/**
 * 通过接口传递实现依赖
 *
 * @author chenwb25485
 * @version V2.1
 * @since 2021/1/21 22:58
 */
public class OpenAndClose {
    public static void main(String[] args) {
        CHANGHONG changhong = new CHANGHONG();
        OpenAndCloseImpl openAndClose = new OpenAndCloseImpl();
        openAndClose.setItv(changhong);
        openAndClose.open();
    }

}


// 通过接口传递实现依赖
/*

interface IOpenAndClose{
    void open(ITV itv);
}

interface ITV {
    void play();
}

class OpenAndCloseImpl implements IOpenAndClose{
    @Override
    public void open(ITV itv) {
        itv.play();
    }
}
class CHANGHONG implements ITV {
    @Override
    public void play() {
        System.out.println("长虹电视正在为您服务");
    }
}*/





// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



// 通过构造方法依赖传递

/*

interface IOpenAndClose{
    void open();
}

interface ITV {
    void play();
}

class OpenAndCloseImpl implements IOpenAndClose{
    ITV itv;

    public OpenAndCloseImpl(ITV itv) {
        this.itv = itv;
    }

    @Override
    public void open() {
        itv.play();
    }
}
class CHANGHONG implements ITV {
    @Override
    public void play() {
        System.out.println("长虹电视正在为您服务");
    }
}
*/



// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



// 通过setter方法依赖传递


interface IOpenAndClose{
    void open();
}

interface ITV {
    void play();
}

class OpenAndCloseImpl implements IOpenAndClose {
    ITV itv;

    public void setItv(ITV itv) {
        this.itv = itv;
    }

    @Override
    public void open() {
        itv.play();
    }
}
class CHANGHONG implements ITV {
    @Override
    public void play() {
        System.out.println("长虹电视正在为您服务");
    }
}

